import axios from 'axios'
import { ElMessage } from 'element-plus'
import { useUserStore } from '@/stroe/modules/user.js'
import cache from '@/utils/cache/index.js'


/// 精简后的 axios 实例配置
const service = axios.create({
  timeout: 60000,
  headers: {
    'Content-Type': 'application/json;charset=UTF-8',
    'Accept-Language': cache.getLanguage()  // 语言设置保留
  }
})

// 精简后的请求拦截器
service.interceptors.request.use(config => {
  const userStore = useUserStore()

  // 仅保留基础 token 注入
  if (userStore?.token) {
    config.headers.Authorization = userStore.token
  }

  // 移除时间戳追加逻辑
  return config
})

/*// 精简后的响应拦截器
service.interceptors.response.use(
  response => {
    // 仅处理基础响应
    if (response.status === 200) {
      return response.data?.code === 200 ? response.data : Promise.reject(response.data)
    }
    return Promise.reject(new Error('Request failed'))
  },
  error => {
    ElMessage.error(error.message)
    return Promise.reject(error)
  }
)*/

export default service

